// 用户协议页面
const agreementConfig = require('../../utils/agreement-config');

Page({
  data: {
    agreement: {},
  },
  
  onLoad() {
    // 设置导航栏标题
    wx.setNavigationBarTitle({
      title: '用户协议'
    });
    
    // 优先从缓存中获取用户协议内容，提高加载速度
    try {
      const cachedAgreement = wx.getStorageSync('userAgreement');
      if (cachedAgreement) {
        this.setData({
          agreement: cachedAgreement
        });
      } else {
        // 如果缓存中不存在，则从配置文件获取
        this.setData({
          agreement: agreementConfig.userAgreement
        });
      }
    } catch (e) {
      // 如果获取缓存失败，则从配置文件获取
      this.setData({
        agreement: agreementConfig.userAgreement
      });
    }
  },
  
  /**
   * 页面显示
   */
  onShow() {
    // 页面显示时无延迟立即渲染
    wx.setPageStyle({
      animated: false
    });
  },
  
  /**
   * 页面分享
   */
  onShareAppMessage() {
    return {
      title: '星途小程序用户协议',
      path: '/pages/agreement/user-agreement'
    };
  }
}); 